﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Work.API.Applications.Write.Commands;
using Work.ErrorCode;

namespace Work.API.Controllers
{
    /// <summary>
    /// Patient-API控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class PatientController : ControllerBase
    {
        private readonly IMediator mediator;
        private readonly ILogger<PatientController> logger;

        public PatientController(IMediator mediator,ILogger<PatientController> logger)
        {
            this.mediator = mediator;
            this.logger = logger;
        }
        /// <summary>
        /// 添加就诊人(办理卡号)
        /// </summary>
        /// <param name="request">请求</param>
        /// <returns>返回添加任务</returns>
        [HttpPost]
        public async Task<ApiResult<Work.API.Dtos.AddPatientResultDto>> AddPatient(AddPatientCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 根据卡号获取就诊人信息
        /// </summary>
        /// <param name="cardNumber">卡号</param>
        /// <returns>就诊人</returns>
        [HttpGet]
        public async Task<ApiResult<Work.Domain.Patient?>> GetByCard(string cardNumber)
        {
            try
            {
                var query = new Work.API.Applications.Read.Commands.GetPatientByCardQuery { CardNumber = cardNumber };
                return await mediator.Send(query);
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}
